<template>
  <div class="app-container">
    <div>
      <el-row class="admin-top-g">
        <GButton
          :is-add-show="false"
          :is-edit-show="false"
          :is-del-show="!!(limits.length >=1 && limits.filter(it => it.FName === '删除').length)"
          :lists="options"
          :is-settings-show = "lookSetShow"
          :is-plus-show="!!(limits.length >=1 && limits.filter(it => it.FName === '加载').length)"
          @onAdd="addUser"
          @onEdit="editUser"
          @onDelete="delUser"
          @onPlus="onPlus"
          @selectSettings="selectSettings"
      /></el-row>
      <br>

      <el-row class="common-row">
        <template v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length">
          <el-input
            v-model="keyword"
            clearable
            style="width: 260px;"
            placeholder="请输入关键字"
            @keyup.native.enter="searchUser"
            @change="searchUser"/>
          <el-select v-model="brand" clearable placeholder="请选择品牌" @change="selectBrand">
            <el-option
              v-for="item in fbrandList"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-select v-if="isFstatusShow" v-model="fstatus" :disabled="jxDisabled" clearable filterable placeholder="请选择审核状态" @change="searchUser">
            <el-option
              v-for="item in statusList"
              :key="item.fstatus"
              :label="item.fname"
              :value="item.fstatus"/>
          </el-select>
          <el-button type="primary" icon="el-icon-search" @click="searchUser">搜索</el-button>
        </template>

        <!--
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '导出').length" type="primary" icon="el-icon-download" @click="downData">导出</el-button>
        <el-button type="primary" icon="el-icon-download" @click="handleDownload">下载{{ fmofanName }}模板</el-button> -->

        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '审核').length" type="primary" icon="el-icon-circle-check" @click="check('1')">审核</el-button>
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '反审核').length" type="primary" icon="el-icon-close" @click="check('0')">反审</el-button>

        <el-button type="primary" icon="el-icon-refresh" @click="refresh">刷新 </el-button>
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '导出').length" type="primary" icon="el-icon-download" @click="downData">导出</el-button>
        <el-button v-if="!!(limits.length >=1 && limits.filter(it => it.FName === '生成报价单').length)" type="primary" icon="el-icon-s-data" @click="getMore">生成报价单 </el-button>
        <el-button
          v-if="limits.length >= 1 && limits.filter(it => it.FName === '已完成').length"
          type="primary"
          icon="el-icon-finished"
          @click="finishBtn('1')">已完成</el-button>

      </el-row>
    </div>
    <br>
    <el-table
      v-loading="listLoading"
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      ref="bjTable"
      :data="tableData"
      show-summary
      :summary-method="getSummariesAll"
      :header-cell-style="tableHeaderStyle"
      :height="tableHeight"
      class="tableCss"
      element-loading-text="正在加载"
      border
      highlight-current-row
      @cell-dblclick="cellDbClick"
      @selection-change="handleSelectionChange"
      @current-change="salaryCurrentChange">
      <el-table-column
        type="selection"
        width="55"/>
      <template v-for="item in formThead">
        <el-table-column v-if="item.frpttypeflag ==0" :key="item.fid" :label="item.frepcap" :fixed="item.fixed" :prop="item.frepfld" :width="item.frepwid" align="center" show-overflow-tooltip>

          <template slot-scope="scope">
            <template v-if="item.frephide<=0">
              <template v-if="item.frepfld === 'fstatus'">
                <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                <el-tag v-else size="mini" type="danger">未审</el-tag>
              </template>
              <template v-else-if="item.frepfld === 'fisqr'">
                <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已完成</el-tag>
                <el-tag v-else size="mini" type="danger">未完成</el-tag>
              </template>
              <template v-else-if="Number(item.freptype)===131" size="mini">
                {{ Number(scope.row[item.frepfld]).toFixed(2) }}
              </template>
              <template v-else size="mini">
                {{ scope.row[item.frepfld] }}
              </template>
            </template>
          </template>
        </el-table-column>
      </template>
    </el-table>

    <el-pagination
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :total="total"
      :page-sizes="pagesizes"
      :page-size="pagesize"
      :current-page.sync="currentPage"
      class="jy-pagination"
      style="text-align: center; margin-top: 20px;"
      background
      layout="sizes, prev, pager, next, total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"/>

    <el-dialog v-el-drag-dialog :visible.sync="addUserModal" title="添加／编辑" width="30%">
      <hr style="height:1px;margin-top:-33px;border:none;border-top:1px solid #ddd;" >
      <el-form v-loading="loadingForm" ref="form" :rules="rules" :inline="true" :model="form" label-width="150px" class="form1">

        <el-row >
          <el-col v-for="item in dialogThead" :span="24" :key="item.fid ">

            <el-form-item :label="item.frepcap" :prop="item.frepfld" >
              <template v-if="item.frepmeg == 1">
                <template v-for="base in baseList" v-if="base.name === item.frepfld" >
                  <el-select v-model="form[item.frepfld]" :key="base.name" class="select_el" clearable filterable placeholder="请选择">
                    <el-option
                      v-for="item2 in base[item.frepfld]"
                      :key="item2.finterid"
                      :label="item2.fname"
                      :value="item2.finterid"/>
                  </el-select>
                </template>
              </template>
              <!-- 多文本-->
              <template v-else-if="item.frepmeg == 6" >
                <template >
                  <el-input :rows="3" v-model="form[item.frepfld]" type="textarea" />
                </template>
              </template>
              <!-- 日期框-->
              <template v-else-if="item.frepmeg == 4" >
                <template >
                  <el-date-picker v-model="form[item.frepfld]" style="width:100%" class="date_el" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" />
                </template>
              </template>
              <!-- 禁止编辑-->
              <template v-else-if="item.frepmeg == 5" >
                <template >
                  <el-input v-model="form[item.frepfld]" :disabled="editText"/>
                </template>
              </template>

              <!-- 输入框 -->
              <template v-else >
                <el-input v-model="form[item.frepfld]" />
              </template>
            </el-form-item>
          </el-col>
        </el-row>

        <div class="dialog-footer">
          <el-form-item >
            <el-button :loading="loadingForm" type="primary" @click="confirm" >确认</el-button>
            <el-button @click="addUserModal=false">取消</el-button>
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>

    <!-- 参数配置 -->
    <el-dialog v-el-drag-dialog :visible.sync="configModal" :close-on-click-modal="false" class="config-dialog">
      <head-table
        :config-list="configList"
        :key-value="key"
        @updateConfigData="getUpdateConfigData" />
    </el-dialog>

    <!-- SQL弹窗 -->
    <el-dialog v-el-drag-dialog :visible.sync="dialogSQLModal" :append-to-body="true" title="执行结果">
      <el-form v-loading="loadingFormSQL" ref="formSQL" :rules="rulesSQL" :model="formSQL" label-width="120px">
        <el-form-item label="SQL语句" prop="gzsql">
          <el-input v-model="formSQL.gzsql" :autosize="{ minRows: 14 }" type="textarea" style="width:400px;"/>
        </el-form-item>
        <el-form-item>
          <el-button :loading="loadingFormSQL" type="primary" @click="confirmSQL" >确认</el-button>
          <el-button @click="dialogSQLModal=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 下载模板 -->
    <el-dialog :visible.sync="tableSetExcel" title="提示：信息导出" style="width:30%; margin:auto;">
      <el-button type="primary" @click="downloadFile1()">导出</el-button>
    </el-dialog>

    <!-- SQL弹窗 -->
    <BjdDialog
      :limits="limits"
      :detail-res="bjdData.detailRes"
      :title="bjdData.title"
      :fmodal="bjdData.fmodal"
      :is-jcj-bool="bjdData.isJcjBool"
      @closeBjDialog="closeBjDialog"
      @SaveTable="SaveTable"
      @exportSCBJD="exportSCBJD"/>

    <!-- 公共弹窗 -->
    <el-dialog
      v-el-drag-dialog
      :visible.sync="fcomDialog.fmodal"
      :close-on-click-modal="false"
      :title= "fcomDialog.title"
      class="fcom-dialog"
      @close="closeFcomDialog">
      <div v-if="fcomDialog.isShowToolBar" class="com-dialog-tool">
        <el-button type="primary" @click="exportDetailData('fcomTable',fcomDialog.title)">导出</el-button>
      </div>
      <el-table
        v-loading="fcomDialog.loading"
        id="fcomTable"
        ref="fcomTable"
        :summary-method="getSummaries"
        :header-cell-style="tableHeaderStyle"
        :data="fcomDialog.tableData"
        :show-summary="fcomDialog.showSummary"
        style="margin-top: 10px;"
        max-height="500"
        class="tableCss"
        element-loading-text="正在加载"
        border
        highlight-current-row>
        <el-table-column
          v-for="(item, key) in fcomDialog.formThead"
          :key="key"
          :prop="item"
          :label="item"
          align="center">
          <template slot-scope="scope">{{ scope.row[item] }}</template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 公共弹窗其他 -->
    <el-dialog
      v-el-drag-dialog
      :visible.sync="fcomDialog.cjDetail.fmodal"
      :close-on-click-modal="false"
      :show-close="true"
      :title= "fcomDialog.cjDetail.title"
      class="cb-set-modal"
      width="50%">
      <div v-if="fcomDialog.cjDetail.isShowToolBar" class="com-dialog-tool" style="margin-bottom: 20px;">
        <el-button type="primary" @click="exportDetailData('cbTable', fcomDialog.cjDetail.title)">导出</el-button>
      </div>
      <el-table
        v-loading="fcomDialog.cjDetail.fdetailLoading"
        v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
        id="cbTable"
        ref="cbTable"
        :data="fcomDialog.cjDetail.fdetailData"
        :header-cell-style="tableHeaderStyle"
        max-height="500"
        class="tableCss single-select-table"
        element-loading-text="正在加载"
        border
        highlight-current-row>
        <el-table-column
          type="selection"
          width="55"/>
        <template v-for="item in fcomDialog.cjDetail.detailFormThead">
          <el-table-column
            v-if="item.frpttypeflag ==0"
            :key="item.fid"
            :label="item.frepcap"
            :prop="item.frepfld"
            :width="item.frepwid"
            align="center"
            show-overflow-tooltip>

            <template slot-scope="scope">
              <template v-if="item.frephide<=0">
                <template v-if="item.frepfld === 'fstatus'">
                  <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                  <el-tag v-else size="mini" type="danger">未审</el-tag>
                </template>
                <template v-else size="mini">
                  {{ scope.row[item.frepfld] }}
                </template>
              </template>
            </template>

          </el-table-column>
        </template>
      </el-table>
    </el-dialog>

  </div>
</template>
<script>
let FRepKey = ''
let opername = ''
const defaultFormThead = []

import HeadTable from '../salary/headTable/index.vue'
import { configColumn, checkStatus, FstatusCheck } from '../../api/salary'
import { download } from '../../mixins/download.js'
import { common } from '../../mixins/common'
import { pagination } from '../../mixins/pagination'
import { parseTime } from '../../utils/index'
import { tableConfig, apiSql, apiFileSave, downFileUrl } from '../../api/account'
import { genAdd, genDel, genList } from '../../api/gen'
import '../../styles/common.scss'
import { zsbjscd, ScBaoJiaDan, BAOJIAMX } from '../../api/xmbj'
import { XLSXOBJ } from '../../utils/XLSXExportExcel'
import BjdDialog from './bjdDialog/index.vue'
import { Zswancheng } from '../../api/peijian'

export default {
  name: 'Index',
  components: {
    BjdDialog,
    HeadTable
  },
  filters: {
    parseTime(time, type) {
      return parseTime(time, type)
    }
  },
  mixins: [download, common, pagination],
  data() {
    return {
      jxDisabled: false,
      fstatus: '', // 状态
      // 下拉列表
      statusList: [],
      value: '',
      options: [],
      FRepKey: '',
      keyword: '',
      fdeleted: '',
      fdeletedList: [

      ],
      fdeletedListDiaL: [

      ],
      gapTime: '',
      start_time: '',
      end_time: '',

      // 表头、表格设置
      tableData: [],
      tableList: [],
      defaultFormThead: [],
      formThead: defaultFormThead,
      dialogThead: [],
      curData: {},

      listLoading: false,
      list: [],
      configModal: false,
      configLoading: false,

      loadingForm: false,
      configList: [],
      key: 0,
      // SQL弹窗
      dialogSQLModal: false,
      loadingFormSQL: false,
      formSQL: {
        gzsql: ''
      },
      rulesSQL: {

      },

      form: {},
      rules: {

      },
      addUserModal: false,
      // loadingForm: false

      fileList: [],

      // 批量删除
      checkData: [],
      selectedData: [],

      // 用户菜单
      menusList: [],
      limits: [],
      userKey: '',
      fmofanName: '',

      bmwzList: [ // 部门位置
        {
          finterid: 0,
          fname: '钢壳'
        },
        {
          finterid: 1,
          fname: '铝壳'
        },
        {
          finterid: 2,
          fname: '14500'
        }
      ],
      brand: '',
      fbrandList: [
        { label: 'WINGD', value: 'WINGD' },
        { label: 'MAN', value: 'MAN' }
      ],
      upData: {},
      fdeptname: '', // 部门
      bmList: [], // 部门
      xlList: [], // 学历
      zwList: [], // 职务
      xbList: [], // 性别
      lzztList: [],
      fileListBasic: [],
      baseList: [],
      upDataBasic: {},

      // 明细公共弹窗
      fcomDialog: {
        info: [
          { field: 'femissionfee', title: '排放检测费详情', FRepKey: 26019, fdanweibumen: '', isShowToolBar: true },
          { field: 'ftuzhiss', title: '图纸送审费详情', FRepKey: 26020, fdanweibumen: '', isShowToolBar: true },

          { field: 'fdrawingfee', title: '图纸费详情', FRepKey: 26015, fdanweibumen: '', isShowToolBar: true },
          { field: 'fpatentfee', title: '专利费详情', FRepKey: 26004, fdanweibumen: '', isShowToolBar: true },

          { field: 'ftaxsinglezjcl', title: '单台直接材料(含税)详情', FRepKey: 26009, fdanweibumen: '', isShowToolBar: true }, // all:1
          // { field: 'fjiazhangcb', title: '加账成本详情', FRepKey: 26005, fdanweibumen: '', isShowToolBar: true }, // all:1

          { field: 'fweldrg', title: '焊接(直接人工)详情', FRepKey: 26001, fdanweibumen: '', isShowToolBar: true },
          { field: 'fjjgrg', title: '机加工(直接人工)详情', FRepKey: 26001, fdanweibumen: '', isShowToolBar: true },
          { field: 'fzhuangshirg', title: '装试(直接人工)详情', FRepKey: 26001, fdanweibumen: '', isShowToolBar: true },

          { field: 'fweldworkfc', title: '焊接车间(辅材)详情', FRepKey: 26008, fdanweibumen: '', isShowToolBar: true },
          { field: 'fmachineworkfc', title: '机加工车间(辅材)详情', FRepKey: 28006, fdanweibumen: '', isShowToolBar: true },
          { field: 'ftestworkfc', title: '装试车间(辅材)详情', FRepKey: 28007, fdanweibumen: '', isShowToolBar: true },

          { field: 'fjiazhangcbcg', title: '加账采购详情', FRepKey: 26005, fdanweibumen: 1, isShowToolBar: true },
          { field: 'fjiazhangcbjs', title: '加账技术详情', FRepKey: 26023, fdanweibumen: 2, isShowToolBar: true },
          { field: 'fjiazhangcbqt', title: '加账其他详情', FRepKey: 26025, fdanweibumen: 3, isShowToolBar: true },

          // fscramount SCR增加的生产成本
          // fegramount EGR增加的生产成本
          // ficeramount IECR增加生产成本
          { field: 'fscramount', title: 'SCR增加的生产成本详情', FRepKey: 27001, fdanweibumen: '', isShowToolBar: true },
          { field: 'fegramount', title: 'EGR增加的生产成本详情', FRepKey: 27012, fdanweibumen: '', isShowToolBar: true },
          { field: 'ficeramount', title: 'IECR增加生产成本详情', FRepKey: 27006, fdanweibumen: '', isShowToolBar: true },

          // fcutter  特定刀具
          // fchuanjianf  船检费
          // fguanlucbamount  IECR增加管路等材料成本
          //  fworkparted  特定工装-分体发运
          // fworkwhole  特定工装-整体发运
          // fzhijierg 直接人工费(合计)

          { field: 'fcutter', title: '特定刀具详情', FRepKey: 26018, fdanweibumen: '', isShowToolBar: true },
          { field: 'fchuanjianf', title: '船检费详情', FRepKey: 26024, fdanweibumen: '', isShowToolBar: true },
          { field: 'fguanlucbamount', title: 'IECR增加管路等材料成本详情', FRepKey: 27010, fdanweibumen: '', isShowToolBar: true },
          { field: 'fworkparted', title: '特定工装-分体发运详情', FRepKey: 26017, fdanweibumen: '', isShowToolBar: true },
          { field: 'fworkwhole', title: '特定工装-整体发运详情', FRepKey: 26017, fdanweibumen: '', isShowToolBar: true },
          { field: 'fzhijierg', title: '直接人工费(合计)详情', FRepKey: 26001, fdanweibumen: '', isShowToolBar: true },
          { field: 'fweiwaifee', title: '委外费用详情', FRepKey: 26014, fdanweibumen: '', isShowToolBar: true },
          { field: 'fqualitycost', title: '质量成本(交付前)详情', FRepKey: 26013, fdanweibumen: '', isShowToolBar: true },
          { field: 'fsalecost', title: '售后成本详情', FRepKey: 26012, fdanweibumen: '', isShowToolBar: true },
          { field: 'fsdtotal', title: '水电费合计详情', FRepKey: 26011, fdanweibumen: '', isShowToolBar: true },
          { field: 'fyouqifee', title: '油气费详情', FRepKey: 26003, fdanweibumen: '', isShowToolBar: true }
        ],
        showSummary: true,
        fchuanjishe: '',
        row: '',
        fbillnoentry: '',
        fbrand: '',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        FRepKey: 0,
        isShowToolBar: false,
        title: '',
        fjybjbillno: '',
        keyword: '',
        fmodel: '',
        fmodal: false,
        loading: false,
        tableData: [],
        formThead: [],
        // 焊接车间(辅材)    ---- 结构
        cjDetail: {
          fmodel: '',
          fbrand: '',
          fjybjbillno: '',

          isShowToolBar: false,
          title: '',
          FRepKey: 0,
          fdanweibumen: '',

          header: [], // 表头字段（值）
          headerKeys: [], // 表头字段（键） filterVal
          listData: [], // 表体数据
          // keyword: '',
          fmodal: false, // 1
          fdetailKeyword: '', // 1
          fdetailLoading: false, // 1
          detailFormThead: [], // 1
          detailDialogThead: [],
          fdetailData: [], // 1
          fdetailList: []
        }
      },

      detail: '',
      opername: '',
      detailVisible: false,
      editText: false,
      tableSetExcel: false,
      lookSetShow: false,
      oriColumnData: [],

      fstatusCheck: 0,
      isFstatusShow: true,

      bjdData: {
        row: '',
        fmodal: false,
        isJcjBool: false,
        title: '正式报价报价单格式',
        detailRes: {}
      }

    }
  },
  async mounted() {
    // console.log(XLSXOBJ.ExportExcelData, ' XLSXOBJ')
    this.userKey = this.$route.meta.FRepKey
    FRepKey = this.$route.meta.FRepKey
    this.upDataBasic.db = this.globalDb.db
    opername = decodeURIComponent(this.globalDb.fname)
    this.opername = decodeURIComponent(this.globalDb.fname)

    this.upDataBasic.FRepKey = this.$route.meta.FRepKey
    this.lookSetShow = JSON.parse(localStorage.getItem('flookSet'))

    this.upData.db = this.globalDb.db
    this.fmofanName = this.$route.meta.title

    await this.getFstatusCheck()
    await this.getAllData()

    // 菜单列表（权限）
    const menuRes = JSON.parse(localStorage.getItem('setMenuData'))
    this.menusList = menuRes
    if (menuRes.length >= 1) {
      menuRes.map(it => {
        it.children.map(item => {
          if (item.fobjectid === this.userKey) {
            this.$set(this, 'limits', item.child)
          }
        })
      })
    }
  },
  methods: {
    async getFstatusCheck() {
      try {
        const res = await FstatusCheck({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.fstatusCheck = res.Data
        console.log(res, ' res  FstatusCheck')
        if (this.fstatusCheck === 0) {
          this.fstatusCheck = true
          this.jxDisabled = false
          this.statusList = [
            {
              fstatus: 0,
              fname: '全部'
            },
            {
              fstatus: 1,
              fname: '未审'
            },
            {
              fstatus: 2,
              fname: '已审'
            },
            {
              fstatus: 5,
              fname: '已完成'
            }
          ]
        } else if (this.fstatusCheck === 1) {
          this.fstatusCheck = true
          this.jxDisabled = true
          this.statusList = [
            {
              fstatus: 2,
              fname: '已审'
            }
          ]
          this.fstatus = 2
        } else {
          this.jxDisabled = false
          this.fstatusCheck = false
        }
      } catch (err) {
        console.log(err)
      }
    },
    getHj(params, arr) {
      const sums = []
      const { columns, data } = params
      columns.forEach((column, columnIndex) => {
        if (columnIndex === 0) {
          sums[columnIndex] = '合计'
        } else {
          if (arr.indexOf(column.property) >= 0) {
            // console.log(data, 'data', column.property, ' column.property')
            // sums[columnIndex] = this.sumNum(data, column.property)
            let sumTemp = this.sumNum(data, column.property)
            if (sumTemp !== '') {
              if (!isNaN(sumTemp)) {
                sumTemp = Number(sumTemp).toFixed(2)
              }
            }
            // console.log(sumTemp, ' sumTemp')
            sums[columnIndex] = sumTemp
          } else {
            sums[columnIndex] = ''
          }
        }
      })
      // 返回一个二维数组的表尾合计
      sums[sums.length - 1] = Number(sums[sums.length - 1]).toFixed(2)
      return sums
    },
    // 合计
    getSummaries(params) {
      // console.log(this.fcomDialog.FRepKey, ' this.fcomDialog.FRepKey getSummaries')
      this.fcomDialog.showSummary = true
      if (this.fcomDialog.FRepKey === 26003) {
        this.fcomDialog.showSummary = false
        // this.fcomDialog.formThead = ['合计金额']
        return this.getHj(params, ['合计金额'])
        // return this.getHj(params, this.fcomDialog.formThead)
        // return
      } else {
        return this.getHj(params, this.fcomDialog.formThead)
      }
    },
    // // 加账成本合计
    // getJzSummaries(params) {
    //   return this.getHj(params, this.jzcbdetailSettings.detailFormThead)
    // },
    sumNum(list, field) {
      let count = 0
      list.forEach(item => {
        if (!isNaN(Number(item[field]))) {
          count += (Number(item[field]) * 100) / 100
        } else {
          count = ''
        }
      })
      return count
    },

    sumNumAll(list, field) { // DONE
      let sumArr = []
      list.forEach(item => {
        sumArr.push(Number(item[field]))
      })
      if (!sumArr.length) {
        return 0
      }
      let sumList = this.decimal.add(...sumArr)
      return sumList
    },
    // 合计
    getSummariesAll ({ columns, data }) {
      const sums = []
      const arr = []
      this.oriColumnData.forEach((item, itemIndex) => {
        if (item.frepfld && item.frepsum === 1) {
          arr.push(item.frepfld)
        }
      })
      columns.forEach((column, columnIndex) => {
        if (columnIndex === 0) {
          sums[columnIndex] = '合计'
        } else {
          if (arr.indexOf(column.property) >= 0) {
            sums[columnIndex] = this.sumNumAll(data, column.property).toFixed(2)
          } else {
            sums[columnIndex] = ''
          }
        }
      })
      // 返回一个二维数组的表尾合计
      return sums
    },
    async cellDbClick(row, column, cell, event) {
      // console.log(column.id, column.property, column, row, event, 'column')
      // fcomDialog
      switch (column.property) {
        case 'ftaxsinglezjcl': // 单台直接材料(含税)
        // case 'fjiazhangcb': // 单台直接材料(含税)
        // eslint-disable-next-line no-fallthrough
        case 'fyouqifee': // 油气费
        // eslint-disable-next-line no-fallthrough

        // eslint-disable-next-line no-fallthrough
        case 'fjiazhangcbcg': // 加账采购
        case 'fjiazhangcbjs': // 加账技术
        case 'fjiazhangcbqt': // 加账其他
          // eslint-disable-next-line no-fallthrough
          this.fcomDialog.fmodel = row.fmodel
          this.fcomDialog.fbrand = row.fbrand
          this.fcomDialog.fjybjbillno = row.fbillno
          this.fcomDialog.fbillnoentry = row.fbillnoentry
          this.fcomDialog.fmodal = true
          this.fcomDialog.info.map(item => {
            if (item.field === column.property) {
              this.fcomDialog.isShowToolBar = item.isShowToolBar
              this.fcomDialog.title = item.title
              this.fcomDialog.FRepKey = item.FRepKey
              this.fcomDialog.fdanweibumen = item.fdanweibumen
            }
          })

          if (
            column.property === 'ftaxsinglezjcl'
          ) {
            await this.getBAOJIAMX({
              FRepKey: this.fcomDialog.FRepKey,
              opername,
              // fdanweibumen: this.fcomDialog.fdanweibumen,
              fbrand: this.fcomDialog.fbrand,
              fmodel: this.fcomDialog.fmodel,
              fjybjbillno: this.fcomDialog.fjybjbillno,
              all: 1
            })
          } else if (column.property === 'fyouqifee') {
            await this.getBAOJIAMX({
              FRepKey: this.fcomDialog.FRepKey,
              opername,
              fbrand: this.fcomDialog.fbrand,
              fmodel: this.fcomDialog.fmodel,
              fjybjbillno: this.fcomDialog.fjybjbillno
            })
          } else {
            await this.getBAOJIAMX({
              FRepKey: this.fcomDialog.FRepKey,
              opername,
              fdanweibumen: this.fcomDialog.fdanweibumen,
              fbrand: this.fcomDialog.fbrand,
              fmodel: this.fcomDialog.fmodel,
              fjybjbillno: this.fcomDialog.fjybjbillno
            })
          }

          break

          // eslint-disable-next-line no-fallthrough
        case 'fdrawingfee': // 图纸费
        case 'fpatentfee': // 专利费
        case 'fguanlucbamount': // IECR增加管路等材料成本
        case 'femissionfee': // 排放检测费
        case 'ftuzhiss': // 图纸送审费
        case 'fweldrg': // 焊接(直接人工)
        case 'fjjgrg': // 机加工(直接人工)
        case 'fzhuangshirg': // 装试(直接人工)
        case 'fzhijierg':// fzhijierg 直接人工费(合计)
        case 'fworkparted': //  fworkparted  特定工装-分体发运
        case 'fworkwhole':// fworkwhole  特定工装-整体发运
        case 'fcutter': // 特定刀具
        case 'fweiwaifee': // 委外费用详情
        case 'fsalecost': // 售后成本详情
        case 'fqualitycost': // 质量成本(交付前)详情
        case 'fchuanjianf': // 船检费
        case 'fsdtotal': // 水电费合计详情
        case 'fweldworkfc': // 焊接车间(辅材) 26008
        case 'fmachineworkfc': // 机加工车间(辅材) 28006
        case 'ftestworkfc': // 装试车间(辅材) 28007
        case 'fscramount': // SCR增加的生产成本
        case 'fegramount': // EGR增加的生产成本
        case 'ficeramount': // IECR增加生产成本
          this.fcomDialog.cjDetail.fchuanjishe = row.fchuanjishe
          this.fcomDialog.cjDetail.row = row
          this.fcomDialog.cjDetail.fmodel = row.fmodel
          this.fcomDialog.cjDetail.fbrand = row.fbrand
          this.fcomDialog.cjDetail.fjybjbillno = row.fbillno
          this.fcomDialog.cjDetail.fbillnoentry = row.fbillnoentry
          this.fcomDialog.cjDetail.fmodal = true
          this.fcomDialog.info.map(item => {
            if (item.field === column.property) {
              this.fcomDialog.cjDetail.isShowToolBar = item.isShowToolBar
              this.fcomDialog.cjDetail.title = item.title
              this.fcomDialog.cjDetail.FRepKey = item.FRepKey
              this.fcomDialog.cjDetail.fdanweibumen = item.fdanweibumen
            }
          })
          if (column.property === 'fpatentfee') {
            await this.getBAOJIAMXCj({
              FRepKey: this.fcomDialog.cjDetail.FRepKey,
              opername,
              fmodel: this.fcomDialog.cjDetail.fmodel,
              fbrand: this.fcomDialog.cjDetail.fbrand,
              fjybjbillno: this.fcomDialog.cjDetail.fjybjbillno,
              fbillnoentry: this.fcomDialog.cjDetail.fbillnoentry
            })
          } else if (column.property === 'fchuanjianf') {
            await this.getBAOJIAMXCj({
              FRepKey: this.fcomDialog.cjDetail.FRepKey,
              opername,
              fchuansheji: this.fcomDialog.cjDetail.fchuanjishe,
              fmodel: this.fcomDialog.cjDetail.fmodel,
              fbrand: this.fcomDialog.cjDetail.fbrand,
              fjybjbillno: this.fcomDialog.cjDetail.fjybjbillno,
              fbillnoentry: this.fcomDialog.cjDetail.fbillnoentry
            })
            console.log(row, ' row')
            if (row.fchuanjishe === 'DNV') {
              this.fcomDialog.cjDetail.FRepKey = 25005
            }
          } else if (
            column.property === 'fscramount' ||
            column.property === 'fegramount' ||
            column.property === 'ficeramount'
          ) {
            await this.getBAOJIAMXCj({
              FRepKey: this.fcomDialog.cjDetail.FRepKey,
              opername,
              row: this.fcomDialog.cjDetail.row
              // fmodel: this.fcomDialog.cjDetail.fmodel,
              // fbrand: this.fcomDialog.cjDetail.fbrand,
              // fjybjbillno: this.fcomDialog.cjDetail.fjybjbillno,
              // fbillnoentry: this.fcomDialog.cjDetail.fbillnoentry
            })
          } else {
            await this.getBAOJIAMXCj({
              FRepKey: this.fcomDialog.cjDetail.FRepKey,
              opername,
              fmodel: this.fcomDialog.cjDetail.fmodel,
              fbrand: this.fcomDialog.cjDetail.fbrand,
              fjybjbillno: this.fcomDialog.cjDetail.fjybjbillno
            })
          }
          await this.getCjHeadData()
          break
        default:
          break
      }
    },
    closeFcomDialog() {
      this.fcomDialog.title = ''
      this.fcomDialog.FRepKey = 0
      this.fcomDialog.fdanweibumen = ''
      this.fcomDialog.fbrand = ''
      this.fcomDialog.fmodel = ''
      this.fcomDialog.fjybjbillno = ''
      this.fcomDialog.fmodal = false
      this.fcomDialog.showSummary = true
    },
    exportDetailData(refId = 'fcomTable', filename) {
      console.log(refId, ' refId')
      XLSXOBJ.ExportExcelData([refId], filename)
    },
    async getBAOJIAMX(data) {
      try {
        this.fcomDialog.loading = true
        const res = await BAOJIAMX(data)
        if (res.Error === 0) {
          if (res.Data.length) {
            console.log(res.Data, ' res.Data')
            this.fcomDialog.formThead = Object.keys(res.Data[0])
          } else {
            this.fcomDialog.formThead = []
          }
          setTimeout(() => {
            this.fcomDialog.tableData = res.Data
          }, 0)
          this.fcomDialog.loading = false
        }
        // this.key = FRepKey
      } catch (error) {
        this.fcomDialog.loading = false
      }
    },
    async getBAOJIAMXCj(data) {
      try {
        this.fcomDialog.cjDetail.fdetailLoading = true
        const res = await BAOJIAMX(data)
        if (res.Error === 0) {
          this.fcomDialog.cjDetail.fdetailLoading = false

          this.fcomDialog.cjDetail.fdetailList = res.Data
          this.fcomDialog.cjDetail.total = res.total
        }
      } catch (error) {
        this.fcomDialog.cjDetail.fdetailLoading = false
      }
    },
    // 表头数据 车间
    async getCjHeadData() {
      try {
        this.fcomDialog.cjDetail.fdetailLoading = true
        this.fcomDialog.cjDetail.header = []
        this.fcomDialog.cjDetail.headerKeys = []
        this.fcomDialog.cjDetail.listData = []

        // try {
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey: this.fcomDialog.cjDetail.FRepKey
        })
        this.fcomDialog.cjDetail.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            this.fcomDialog.cjDetail.detailFormThead = res.Data
          } else {
            this.fcomDialog.cjDetail.detailFormThead = []
          }
        }
        // 机型  功率 生效台数 流水号
        this.fcomDialog.cjDetail.detailFormThead.map(item => {
          this.fcomDialog.cjDetail.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.fcomDialog.cjDetail.fdetailData = this.fcomDialog.cjDetail.fdetailList.slice()

        // 获取显示表头键值对
        this.fcomDialog.cjDetail.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.fcomDialog.cjDetail.header.push(item.frepcap)
            this.fcomDialog.cjDetail.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.fcomDialog.cjDetail.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.fcomDialog.cjDetail.headerKeys.map(it => {
            this.fcomDialog.cjDetail.listData[index][it] = item[it]
          })
        })

        // console.log(this.fcomDialog.cjDetail.detailFormThead, ' this.fcomDialog.cjDetail.detailFormThead')
        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.fcomDialog.cjDetail.fdetailLoading = false
      }
    },

    onPlus() {
      this.$router.push('/baojia/caculateCb')
    },
    closeBjDialog(bool) {
      this.bjdData.fmodal = bool
      // this.bjdData.title = ''
      this.bjdData.detailRes = {}
    },
    async SaveTable(idBody) {
      const tr = document.querySelectorAll('.inputClass')
      const fObj = {}
      for (let i = 0; i < tr.length; i++) {
        const desc = tr[i].getAttribute('desc')
        const trHtml = tr[i].value
        fObj[desc] = trHtml
      }
      // console.log(fObj, ' fObj')
      const selectData = this.selectedData[0]
      await this.getZsbjscd(selectData, fObj)
    },
    async getZsbjscd(selectData, fObj) {
      try {
        const res = await zsbjscd({
          FRepKey,
          opername: decodeURIComponent(this.globalDb.fname),
          fid: selectData.fid,
          data: fObj,
          fbillno: selectData.fbillno

        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
        } else {
          this.$message({
            message: res.Message,
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
    exportSCBJD(id) {
      // console.log(this.bjdData.row, ' this.bjdData.row')
      let title =  this.bjdData.row.fcustomer +'_'+ this.bjdData.row.fmodel+'_'+ this.bjdData.row.fbillno
      let baseStr = '_'+this.bjdData.row.fmodel+'_'+ this.bjdData.row.fbillno.slice(-4) 
      //31 chars
      if( title.length > 31 ){
        title = this.bjdData.row.fcustomer.slice(0,31-baseStr.length ) +'_'+ this.bjdData.row.fmodel+'_'+ this.bjdData.row.fbillno.slice(-4)
      }

      // Sheet name cannot contain : \ / ? * [ ]
      title = title.replace('/', '')
      title = title.replace('\\', '')

      title = title.replace('?', '')
      title = title.replace('*', '')

      title = title.replace('<', '')
      title = title.replace('>', '')

      title = title.replace('[', '')
      title = title.replace(']', '')

      title = title.replace('|', '')
      title = title.replace('"', '')

      console.log(111111 , title , title.length )
     

      XLSXOBJ.ExportExcelData([id], title)
    },

    // subStringResult(str, len) {
    //   var newLength = 0
    //   var newStr = ''
    //   var chineseRegex = '/[^\x00-\xff]/g'
    //   var singleChar = ''
    //   var strLength = str.replace(chineseRegex, '**').length
    //   for (var i = 0; i < strLength; i++) {
    //     singleChar = str.charAt(i).toString()
    //     if (singleChar.match(chineseRegex) != null) {
    //       newLength += 2
    //     } else {
    //       newLength++
    //     }
    //     if (newLength > len) {
    //       break
    //     }
    //     newStr += singleChar
    //   }

    //   if (strLength > len) {
    //     newStr += '...'
    //   }
    //   return newStr
    // },

    async getScBaoJiaDanNew(fid) {
      try {
        const res = await ScBaoJiaDan({
          FRepKey,
          opername: decodeURIComponent(this.globalDb.fname),
          fbillno: this.selectedData[0].fbillno,
          fid
        })
        if (res.Error === 0) {
          this.bjdData.detailRes = res.Data
        } else {
          this.$message({
            message: res.Message,
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
    async getMore() {
      if (this.selectedData.length !== 1) {
        this.$message({
          message: '请选中一行',
          type: 'warning'
        })
        return
      }
      // console.log(this.bjdData, ' this.bjdData')
      this.bjdData.fmodal = true
      this.bjdData.row = this.selectedData[0]
      const data = this.selectedData[0]
      console.log(data.fmodel.indexOf('LGIM'), ' data')
      if (data.fmodel.indexOf('LGIM') > -1) {
        this.bjdData.isJcjBool = true
      } else {
        this.bjdData.isJcjBool = false
      }
      await this.getScBaoJiaDanNew(data.fid)
    },
    // 刷新
    refresh() {
      window.location.reload()
    },

    async toDetail(data) {
      this.detailVisible = true
      this.detail = data
    },

    selectFBirthday(val) {
      this.form.fbirthday = parseTime(val, '{y}-{m}-{d}')
    },
    selectFHireDate(val) {
      this.form.fhiredate = parseTime(val, '{y}-{m}-{d}')
    },
    selectFLeaveDate(val) {
      this.form.fleavedate = parseTime(val, '{y}-{m}-{d}')
    },
    // 表头数据
    async getAllHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.oriColumnData = res.Data
        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        // this.tableData = this.tableList.slice()
        let tableTemp
        if (this.selectedData.length) {
          tableTemp = this.selectedData
        } else {
          tableTemp = this.tableList.slice()
        }

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        // const listData = this.tableList.slice()
        const listData = tableTemp.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    async getAllBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,
          brand: this.brand,

          fstatus: this.fstatus,
          limit: this.total,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false

        this.tableList = res.Data
        this.total = res.total
      } catch (error) {
        this.listLoading = false
      }
    },
    // 导出数据
    async downData() {
      await this.getAllBodyData()
      await this.getAllHeadData()
      await this.exportData()
    },
    async getAllData() {
      await this.getBodyData()
      await this.getHeadData()
    },

    selectSettings(val) {
      if (val === 0) {
        this.settings()
      } else if (val === 1) {
        this.dialogSQL()
      }
    },
    settings() {
      this.configModal = true
      this.getTableConfig()
    },

    // 更新数据
    async getUpdateConfigData() {
      await this.getTableConfig()
      await this.getBodyData()
      await this.getHeadData()
    },

    // SQL修改/更新
    async dialogSQL() {
      this.dialogSQLModal = true
      try {
        const res = await apiSql({
          db: this.globalDb.db,
          opername,
          FRepKey
        })

        if (res.Error === 0) {
          this.formSQL.gzsql = res.Data
          this.formSQL.FRepKey = FRepKey
        }
        setTimeout(() => {
          this.$refs['formSQL'].clearValidate()
        })
      } catch (error) {
        // console.log(error)
      }
    },

    confirmSQL() {
      this.$refs['formSQL'].validate(async(valid) => {
        if (valid) {
          try {
            this.formSQL.db = this.globalDb.db
            this.formSQL.opername = opername
            const res = await apiFileSave(this.formSQL)
            if (res.Error === 0) {
              this.dialogSQLModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            // console.log(error)
          }
        } else {
          return false
        }
      })
    },

    async getTableConfig() {
      try {
        this.configLoading = true
        const res = await tableConfig({
          db: this.globalDb.db,
          opername,
          key: FRepKey
        })
        this.configList = res.Data
        this.key = FRepKey
        this.configLoading = false
      } catch (error) {
        this.configLoading = false
      }
    },

    // 表头数据
    async getHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.oriColumnData = res.Data
        // this.tableList = []
        this.formThead.map(item => {
          // console.log(item, ' item')
          // fisqr 是否完成
          // fstatus 审核
          // fbillno 单号
          // fbrand 品牌
          // fcustomer 项目客户
          // fmodel 机型
          // funit 计量单位
          // fqty 生效台数
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
            if (
              item.frepfld === 'fisqr' ||
              item.frepfld === 'fstatus' ||
              item.frepfld === 'fbillno' ||
              item.frepfld === 'fbrand' ||
              item.frepfld === 'fcustomer' ||
              item.frepfld === 'fmodel' ||
              // item.frepfld === 'funit' ||
              item.frepfld === 'fqty'
            ) {
              item.fixed = true
            }
          })
        })
        this.tableData = this.tableList.slice()

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.tableList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    async getBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,
          brand: this.brand,

          fstatus: this.fstatus,
          limit: this.pagesize,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false

        this.tableList = res.Data
        this.total = res.total
      } catch (error) {
        this.listLoading = false
      }
    },
    async selectBrand() {
      await this.searchUser()
    },
    async searchUser() {
      await this.getAllData()
    },
    async handleSizeChange(val) {
      this.currentPage = 1
      this.pagesize = val
      await this.getAllData()
    },
    async handleCurrentChange(val) {
      this.currentPage = val
      await this.getAllData()
    },
    salaryCurrentChange(val) {
      this.curData = val
    },

    // 下载
    async handleDownload() {
      const res = await downFileUrl({
        db: this.globalDb.db,
        opername,
        FRepKey
      })
      if (res.Error === 0) {
        this.tableSetExcel = true
        this.url = res.Data
      } else {
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }
    },

    downloadFile1() {
      this.tableSetExcel = false
      window.open('/api/downloadFile?FRepKey=' + FRepKey)
    },

    // -----------------上传模板开始---------------------
    // 添加
    async addUser() {
      this.editText = false
      this.form = {}
      const data = {}
      this.dialogThead.map(item => { data[item.frepfld] = '' })
      for (const i in data) {
        this.$set(this.form, i, data[i])
      }
      setTimeout(() => {
        this.$refs['form'].clearValidate()
      })

      this.addUserModal = true
    },

    // 修改
    async editUser() {
      const data = this.selectedData[0]
      if (data && Number(data.fstatuscb) === 1) {
        this.$message({
          message: '已审核，不能修改！',
          type: 'error'
        })
        return
      }

      this.editText = true
      this.form = {}
      if (this.selectedData.length !== 1) {
        this.$message({
          message: '请选中要编辑的一行',
          type: 'warning'
        })
        return
      }

      this.dialogThead.map(item => { this.$set(this.form, item.frepfld, '') })
      this.form.fid = 0
      this.addUserModal = true
      for (const i in this.form) {
        this.form[i] = data[i]
        this.dialogThead.map(item => {
          if (item.frepmeg === 1 && i === item.frepfld && !data[i]) {
            this.form[i] = ''
          }
        })
      }

      setTimeout(() => {
        this.$refs['form'].clearValidate()
      })
    },

    async confirm() {
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          this.loadingForm = true
          try {
            this.form.db = this.globalDb.db
            this.form.opername = opername
            this.form.FRepKey = FRepKey

            const res = await genAdd(this.form)
            if (res.Error === 0) {
              this.loadingForm = false
              this.addUserModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })

              await this.getAllData()
            } else {
              this.loadingForm = false

              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            this.loadingForm = false
          }
        } else {
          return false
        }
      })
    },

    async delUser() {
      const data = this.checkData
      if (data.length < 1) {
        this.$message({
          message: '请选中要删除的一行',
          type: 'warning'
        })
        return
      }

      const dataTemp = this.selectedData
      const isFstatus = dataTemp.filter(it => Number(it.fstatus) === 1)

      if (isFstatus.length) {
        this.$message({
          message: '已审核，不能删除！',
          type: 'error'
        })
        return
      }

      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning'
      }).then(async() => {
        const fid = data.join(',')
        const res = await genDel({
          db: this.globalDb.db,
          opername,
          data: this.selectedData,
          fid: fid,
          FRepKey

        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          await this.getAllData()
          return
        }
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    // 1—审核，0—反审
    async check(Fstatus) {
      if (!this.checkData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      if (Number(Fstatus) === 1) {
        this.$confirm('是否审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          cancelButtonClass: 'btn-custom-cancel',
          type: 'warning'
        }).then(async() => {
          try {
            const res = await checkStatus({
              db: this.globalDb.db,
              loginname: decodeURIComponent(this.globalDb.fname),
              opername: decodeURIComponent(this.globalDb.fname),
              FRepKey,
              Fstatus, // 1—审核，0—反审
              fid: this.checkData.join(','),
              data: this.selectedData

            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
              await this.getAllData()
            } else {
              this.loadingForm = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      } else {
        try {
          const res = await checkStatus({
            db: this.globalDb.db,
            loginname: decodeURIComponent(this.globalDb.fname),
            opername: decodeURIComponent(this.globalDb.fname),
            FRepKey,
            Fstatus, // 1—审核，0—反审
            fid: this.checkData.join(','),
            appname: '',
            data: this.selectedData
          })
          if (res.Error === 0) {
            this.$message({
              message: res.Message,
              type: 'success'
            })
            await this.getAllData()
          } else {
            this.loadingForm = false
            this.$message({
              message: res.Message,
              type: 'error'
            })
          }
        } catch (error) {
          console.log(error)
        }
      }
    },
    async finishBtn(fisqr) {
      // const chData = this.selectedData[0]
      if (!this.selectedData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      const fids = this.selectedData.map(it => it.fid)
      // console.log(fids, ' fids')
      // return
      try {
        const res = await Zswancheng({
          db: this.globalDb.db,
          fid: fids.join(','),
          fisqr, // 1—已完成，0—未完成
          opername,
          data: this.selectedData,
          FRepKey
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          await this.getAllData()
          this.selectedData = []
          this.$refs.bjTable.clearSelection()
        } else {
          this.loadingForm = false
          this.$message({
            message: res.Message,
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
    handleSelectionChange(val) {
      // console.log(val, ' val')
      this.checkData = []
      this.selectedData = val
      val.map(it => {
        this.checkData.push(it.fid)
      })
    }

  }
}

</script>
<style lang="scss" scoped>
.config-dialog ::v-deep .el-dialog {
  width: 90%;
}
  .config-dialog ::v-deep .el-dialog__body {
    padding: 0 20px;
    height: 600px;
  }

  .cb-set-modal ::v-deep .el-dialog__body {
    min-height: 350px!important;
    overflow: scroll;
  }
  .cb-set-modal ::v-deep .single-select-table thead .el-table-column--selection .cell {
    display: none;
  }

  ::v-deep .finput-dialog.el-dialog__wrapper  .el-dialog__body {
    height: 150px;
  }
  .config-dialog ::v-deep .el-dialog__body {
    padding: 0 20px;
    height: 600px;
  }
  .cb-set-modal ::v-deep .el-dialog__body {
    padding: 0 20px;
    // height: 600px;
  }
.fcom-dialog ::v-deep .el-dialog {
  width: 90%;
}
.fcom-dialog ::v-deep .el-dialog__body {
  padding: 0 20px;
  // height: 600px;
}

::v-deep .el-table__body-wrapper{
       z-index: 2
}
::v-deep .el-table__fixed-footer-wrapper tbody td.custom-cell{
	border-right: 1px solid #DBDFE5 !important;
}
 
</style>
